def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def samoeblo(n):
    if not 1000 <= n <= 9999:
        return 0

    n = str(n)
    max = 0
    for i in range(len(n)):
        for j in range(i + 1, len(n) + 1):
            num = int(n[i:j])
            if is_prime(num) and num > max:
                max = num
    return max

n = int(input("Число4х: "))
print(samoeblo(n))


